import { cloud, CloudDBCollection } from '@hw-agconnect/cloud-server';//引入Server SDK依赖
import { BookInfo } from './BookInfo'; //BookInfo为对象类型名

// ZONE_NAME为存储区名称
const ZONE_NAME = "QuickStartDemo";

export class CloudDbZoneWrapper {
  collection: CloudDBCollection<BookInfo>;

  constructor() {
    this.collection = cloud.database({ zoneName: ZONE_NAME }).collection(BookInfo);
  }

  //查询数据
  async queryBooks() {
    let query = this.collection.query();
    return await query.get();
  }

  //更新数据
  async upsertBooks(records: BookInfo[]) {
    return await this.collection.upsert(records);
  }

  //删除数据
  async deleteBooks(records: BookInfo[]) {
    return await this.collection.delete(records);
  }
}